package top.bugger168.content.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.bugger168.content.model.dto.BindTeachplanMediaDto;
import top.bugger168.content.model.dto.SaveTeachplanDto;
import top.bugger168.content.model.dto.TeachplanDto;
import top.bugger168.content.model.po.TeachplanMedia;
import top.bugger168.content.service.TeachplanService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 课程计划编辑接口
 *
 * @author wanghaidong
 * @date 2023/08/28
 */
@Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
@RestController
public class TeachplanController {
    @Resource
    TeachplanService teachplanService;

    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId",name = "课程id",required = true,dataType = "Long",paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){
        return teachplanService.findTeachplanTree(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan( @RequestBody @Validated SaveTeachplanDto teachplan){
        teachplanService.saveTeachplan(teachplan);
    }

    @ApiOperation("课程计划删除")
    @DeleteMapping("/teachplan/{teachplanId}")
    public void deleteTeachplan(@PathVariable Long teachplanId){
        teachplanService.removeTeachplan(teachplanId);
    }

    @ApiOperation("课程计划上移")
    @PostMapping("/teachplan/moveup/{teachplanId}")
    public void moveup(@PathVariable Long teachplanId){
        teachplanService.moveupTeachplan(teachplanId);
    }

    @ApiOperation("课程计划上移")
    @PostMapping("/teachplan/movedown/{teachplanId}")
    public void movedown(@PathVariable Long teachplanId){
        teachplanService.movedownTeachplan(teachplanId);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public TeachplanMedia associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        return teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "课程计划和媒资信息解绑")
    @DeleteMapping("/teachplan/association/media/{teachplanId}/{mediaId}")
    public void associationMedia(@PathVariable(required = false) Long teachplanId, @PathVariable String mediaId){
        // 本来这个接口只需要一个teachplanId就可以实现
        // md狗前端不给我传参数,teachplanId是null,只能通过mediaId来删
        teachplanService.cutMedia(teachplanId,mediaId);
    }


}
